# 19.py
# 迭代器1

l = [1, 2, 3]
for i in iter(l):
  print(i)

# class Person:
# 
#   def __init__(self):
#     self.result = 1
# 
#   def __getitem__(self,item):
#     self.result += 1
#     if self.result >= 6:
#       raise StopIteration('停止遍历')
#     return self.result
# 
#   pass
# 
# p = Person()
# 
# for i in p:
#   print(i)


class Person:

  def __init__(self):
    self.result = 1

  def __getitem__(self,item):
    print('getitem')
    self.result += 1
    if self.result >= 6:
      raise StopIteration('停止遍历')
    return self.result

  def __iter__(self):
    return iter([1,2,3,4,5])


  pass

p = Person()

for i in p:
  print(i)


